A small update has been made to the way that comments are displayed, particularly the way that comment threading is handled. While it did involve a fair amount of work behind the scenes, the visible changes are largely aesthetic – everything should continue to work the same way. This is mainly just a quick heads-up in case anyone spots problems resulting from the changes (if so, please let me know in the comments).
If anyone is interested in the reasons for the change, or the technical details, please “read more.”
The previous threaded comments display was handled by a WordPress add-on called YATCP (Yet Another Threaded Comments Plugin). It worked fairly well, but it shared a general WordPress trait that I’m not overly fond of: an insistence on outputting everything as an unordered list, which meant that all the comments were displayed as list items. I wanted a slightly more “traditional” threading display and I couldn’t figure out a way to do that using unordered lists and list items.
Here’s quick before-and-after comparison:
Before |
After |
Since I couldn’t get the exact display I wanted through YATCP, I decided to take a stab at using PHP to query the database directly and display the comments as divs instead of list items.
It turned out to be one of those things that are much more difficult than they seem at first glance – mainly because I couldn’t find any way to construct a single query for listing all of the “child” comments belonging to a particular parent comment. The eventual solution I hit on was:
– query for all comments that are linked to a particular post and have no parent comment (which effectively retrieves all the parent comments)
– run a “while” loop to display the parent comments, and also query for any child comments
– if there are any child comments, then a nested “while” loop runs to display them
– at the end of the nested “while” loop, there is another query to check for “sub-child” comments (replies to replies)
– if there are sub-child comments, then a “require()” statement runs, calling an external “child-comments.php” file to display the sub-child comments
– at the end of the external file, there is a query to check for replies to each sub-child post
– if any results are found, then another require statement runs – this one calling the “child-comments.php” file itself
So, in a nutshell, I have a file that uses “require()” to call an external file – and the external file, in turn, requires itself. Basically the programmatic equivalent of a snake eating itself. It’s a gigantic kludge, but it seems to work.
If anyone would like a copy of the code, just let me know.
Category: News - Comments RSS - Post a Comment - Trackback |
« Haiku developers want native browser | New Info on Haiku WiFi Stack » |